package com.btex.app.treaty.list;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.btex.app.R;
import com.btex.app.entity.TreatyDishListInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/16
 * @time 下午12:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class EntrustListbuyAdapter extends BaseQuickAdapter<TreatyDishListInfo.DataBean.LongBean, BaseViewHolder> {

    private double mMax;
    private String mChangeType;
    private String mNumbers;
    private String mReverse;
    private String mIsreverseNumber;
    private String mContractvalue = "1";

    public EntrustListbuyAdapter(@Nullable List<TreatyDishListInfo.DataBean.LongBean> data) {
        super(R.layout.fragment_entrust_list_buy, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TreatyDishListInfo.DataBean.LongBean item) {

        TextView item_treaty_tv_buy_price = (TextView) helper.getView(R.id.item_treaty_tv_buy_price);
        TextView item_treaty_tv_buy_number = (TextView) helper.getView(R.id.item_treaty_tv_buy_number);
        ProgressBar fragment_entrust_pro_buy = (ProgressBar) helper.getView(R.id.fragment_entrust_pro_buy);

        fragment_entrust_pro_buy.setMax((int) mMax);
        fragment_entrust_pro_buy.setProgress(Integer.valueOf(item.getAmount()));


        if (!TextUtils.isEmpty(mNumbers)) {

            Log.i("woifjowiejfowfe", mNumbers);
            String trim = Tools.round(Double.valueOf(item.getPrice()), Integer.valueOf(mNumbers)).toString().trim();
            item_treaty_tv_buy_price.setText(trim);

        } else {

            if (!TextUtils.isEmpty(item.getPrice())) {
                String price = item.getPrice();
                String[] split = price.split("\\.");
                String s = split[1];
                if (s.length() > 4) {
                    String substring = s.substring(0, 4);
                    String s1 = split[0] + "." + substring;
                    item_treaty_tv_buy_price.setText(s1);
                } else {
                    item_treaty_tv_buy_price.setText(item.getPrice());
                }


            }

        }


        if (mChangeType.equals("1")) {


            item_treaty_tv_buy_number.setText(item.getAmount());


        } else {

            String amount = item.getAmount();
            String price = item.getPrice();

            if (!TextUtils.isEmpty(mReverse)) {


                if ("1".equals(mReverse)) {

                    Double aDoubleamount = Double.valueOf(amount);
                    Double aDoubleprice = Double.valueOf(price);
                    double v = aDoubleamount / aDoubleprice * Double.valueOf(mContractvalue);
                    if (!TextUtils.isEmpty(mIsreverseNumber)) {
                        String trim = Tools.round(v, Integer.valueOf(mIsreverseNumber)).toString().trim();
                        item_treaty_tv_buy_number.setText(trim);
                    }

                } else {

                    Double aDoubleamount = Double.valueOf(amount);
                    Double aDoubleprice = Double.valueOf(price);
                    double v = aDoubleamount * aDoubleprice * Double.valueOf(mContractvalue);

                    if (!TextUtils.isEmpty(mIsreverseNumber)) {

                        String trim = Tools.round(v, Integer.valueOf(mIsreverseNumber)).toString().trim();
                        item_treaty_tv_buy_number.setText(trim);
                    }


                }


            }

        }

//        item_treaty_tv_buy_price.setText(item.getPrice());


    }


    public void SetValue(double max) {

        this.mMax = max;
    }

    public void settype(String Type) {


        this.mChangeType = Type;
    }


    public void setNumber(String numbers) {

        mNumbers = numbers;
    }

    public void setIsreverse(String reverse) {

        mReverse = reverse;
    }

    public void setIsreverseNumber(String IsreverseNumber) {

        mIsreverseNumber = IsreverseNumber;
    }

    public void setContractValue(String contractvalue) {

        mContractvalue = contractvalue;
    }


}
